package com.meeting.y.task;

import com.alibaba.fastjson.JSON;
import com.jfinal.kit.HttpKit;
import com.jfinal.plugin.cron4j.ITask;
import com.meeting.y.util.StringUtil;
import com.meeting.y.util.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class RemindHealth implements ITask {
    Logger logger= LoggerFactory.getLogger(RemindHealth.class);

    String url = "";

    public RemindHealth(){

    }

    public RemindHealth(String initurl){
        url = initurl;
    }

    @Override
    public void stop() {

    }

    @Override
    public void run() {


        String DELETE_URL =  url;
        if(StringUtil.isStrEmpty(DELETE_URL)) {
            DELETE_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3ea3b490-91a9-48aa-997c-a41c66f9ac65";
        }
        /*{
            "msgtype": "text",
                "text": {
            "content": "广州今日天气：29度，大部分多云，降雨概率：60%",
            "mentioned_list":["wangqing","@all"],
            "mentioned_mobile_list":["13800001111","@all"]
            }
        }*/
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("msgtype","markdown");
        int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        Map<String, String> markdown = new HashMap<String, String>();
        if(hour>10){
            markdown.put("content","###### 那个谁谁谁，就差你的健康上报了！！");
        }else {
            markdown.put("content","###### 广发健康上报\n  [点击上报](https://support.gf.com.cn/healthreport/#/?type=3&role=2&dpname=%E4%BF%A1%E6%81%AF%E6%8A%80%E6%9C%AF%E9%83%A8)\n");
        }
        map.put("markdown", markdown);
        String[] strs = {"@all"};
        map.put("mentioned_list",strs);
        String msg = "";
        logger.debug("msg:"+JSON.toJSONString(map));
        msg = HttpKit.post(DELETE_URL , JSON.toJSONString(map));
        logger.debug("returnmsg:"+msg);
    }
}
